/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package GM.impl;

import GM.ContributionLink;
import GM.Definition;
import GM.GMPackage;
import GM.Goal;
import GM.Operation;
import GM.RefinementLink;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Goal</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link GM.impl.GoalImpl#getDescription <em>Description</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#isLeaf <em>Leaf</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#getPriority <em>Priority</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#getRef <em>Ref</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#getSonOf <em>Son Of</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#getContr <em>Contr</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#getOperat <em>Operat</em>}</li>
 *   <li>{@link GM.impl.GoalImpl#getDefinition <em>Definition</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class GoalImpl extends ObjectImpl implements Goal {
	/**
	 * The default value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected static final String DESCRIPTION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected String description = DESCRIPTION_EDEFAULT;

	/**
	 * The default value of the '{@link #isLeaf() <em>Leaf</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isLeaf()
	 * @generated
	 * @ordered
	 */
	protected static final boolean LEAF_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isLeaf() <em>Leaf</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isLeaf()
	 * @generated
	 * @ordered
	 */
	protected boolean leaf = LEAF_EDEFAULT;

	/**
	 * The default value of the '{@link #getPriority() <em>Priority</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPriority()
	 * @generated
	 * @ordered
	 */
	protected static final int PRIORITY_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getPriority() <em>Priority</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPriority()
	 * @generated
	 * @ordered
	 */
	protected int priority = PRIORITY_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRef() <em>Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRef()
	 * @generated
	 * @ordered
	 */
	protected RefinementLink ref;

	/**
	 * The cached value of the '{@link #getSonOf() <em>Son Of</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSonOf()
	 * @generated
	 * @ordered
	 */
	protected RefinementLink sonOf;

	/**
	 * The cached value of the '{@link #getContr() <em>Contr</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getContr()
	 * @generated
	 * @ordered
	 */
	protected EList<ContributionLink> contr;

	/**
	 * The cached value of the '{@link #getOperat() <em>Operat</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOperat()
	 * @generated
	 * @ordered
	 */
	protected EList<Operation> operat;

	/**
	 * The cached value of the '{@link #getDefinition() <em>Definition</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDefinition()
	 * @generated
	 * @ordered
	 */
	protected Definition definition;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GoalImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GMPackage.Literals.GOAL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDescription(String newDescription) {
		String oldDescription = description;
		description = newDescription;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__DESCRIPTION, oldDescription, description));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isLeaf() {
		return leaf;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLeaf(boolean newLeaf) {
		boolean oldLeaf = leaf;
		leaf = newLeaf;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__LEAF, oldLeaf, leaf));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPriority() {
		return priority;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPriority(int newPriority) {
		int oldPriority = priority;
		priority = newPriority;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__PRIORITY, oldPriority, priority));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RefinementLink getRef() {
		if (ref != null && ref.eIsProxy()) {
			InternalEObject oldRef = (InternalEObject)ref;
			ref = (RefinementLink)eResolveProxy(oldRef);
			if (ref != oldRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, GMPackage.GOAL__REF, oldRef, ref));
			}
		}
		return ref;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RefinementLink basicGetRef() {
		return ref;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRef(RefinementLink newRef, NotificationChain msgs) {
		RefinementLink oldRef = ref;
		ref = newRef;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__REF, oldRef, newRef);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRef(RefinementLink newRef) {
		if (newRef != ref) {
			NotificationChain msgs = null;
			if (ref != null)
				msgs = ((InternalEObject)ref).eInverseRemove(this, GMPackage.REFINEMENT_LINK__MY_FATHER, RefinementLink.class, msgs);
			if (newRef != null)
				msgs = ((InternalEObject)newRef).eInverseAdd(this, GMPackage.REFINEMENT_LINK__MY_FATHER, RefinementLink.class, msgs);
			msgs = basicSetRef(newRef, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__REF, newRef, newRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RefinementLink getSonOf() {
		if (sonOf != null && sonOf.eIsProxy()) {
			InternalEObject oldSonOf = (InternalEObject)sonOf;
			sonOf = (RefinementLink)eResolveProxy(oldSonOf);
			if (sonOf != oldSonOf) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, GMPackage.GOAL__SON_OF, oldSonOf, sonOf));
			}
		}
		return sonOf;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RefinementLink basicGetSonOf() {
		return sonOf;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSonOf(RefinementLink newSonOf, NotificationChain msgs) {
		RefinementLink oldSonOf = sonOf;
		sonOf = newSonOf;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__SON_OF, oldSonOf, newSonOf);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSonOf(RefinementLink newSonOf) {
		if (newSonOf != sonOf) {
			NotificationChain msgs = null;
			if (sonOf != null)
				msgs = ((InternalEObject)sonOf).eInverseRemove(this, GMPackage.REFINEMENT_LINK__TARGET, RefinementLink.class, msgs);
			if (newSonOf != null)
				msgs = ((InternalEObject)newSonOf).eInverseAdd(this, GMPackage.REFINEMENT_LINK__TARGET, RefinementLink.class, msgs);
			msgs = basicSetSonOf(newSonOf, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__SON_OF, newSonOf, newSonOf));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ContributionLink> getContr() {
		if (contr == null) {
			contr = new EObjectResolvingEList<ContributionLink>(ContributionLink.class, this, GMPackage.GOAL__CONTR);
		}
		return contr;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Operation> getOperat() {
		if (operat == null) {
			operat = new EObjectResolvingEList<Operation>(Operation.class, this, GMPackage.GOAL__OPERAT);
		}
		return operat;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Definition getDefinition() {
		return definition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDefinition(Definition newDefinition, NotificationChain msgs) {
		Definition oldDefinition = definition;
		definition = newDefinition;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__DEFINITION, oldDefinition, newDefinition);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDefinition(Definition newDefinition) {
		if (newDefinition != definition) {
			NotificationChain msgs = null;
			if (definition != null)
				msgs = ((InternalEObject)definition).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GMPackage.GOAL__DEFINITION, null, msgs);
			if (newDefinition != null)
				msgs = ((InternalEObject)newDefinition).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GMPackage.GOAL__DEFINITION, null, msgs);
			msgs = basicSetDefinition(newDefinition, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GMPackage.GOAL__DEFINITION, newDefinition, newDefinition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GMPackage.GOAL__REF:
				if (ref != null)
					msgs = ((InternalEObject)ref).eInverseRemove(this, GMPackage.REFINEMENT_LINK__MY_FATHER, RefinementLink.class, msgs);
				return basicSetRef((RefinementLink)otherEnd, msgs);
			case GMPackage.GOAL__SON_OF:
				if (sonOf != null)
					msgs = ((InternalEObject)sonOf).eInverseRemove(this, GMPackage.REFINEMENT_LINK__TARGET, RefinementLink.class, msgs);
				return basicSetSonOf((RefinementLink)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GMPackage.GOAL__REF:
				return basicSetRef(null, msgs);
			case GMPackage.GOAL__SON_OF:
				return basicSetSonOf(null, msgs);
			case GMPackage.GOAL__DEFINITION:
				return basicSetDefinition(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GMPackage.GOAL__DESCRIPTION:
				return getDescription();
			case GMPackage.GOAL__LEAF:
				return isLeaf();
			case GMPackage.GOAL__PRIORITY:
				return getPriority();
			case GMPackage.GOAL__REF:
				if (resolve) return getRef();
				return basicGetRef();
			case GMPackage.GOAL__SON_OF:
				if (resolve) return getSonOf();
				return basicGetSonOf();
			case GMPackage.GOAL__CONTR:
				return getContr();
			case GMPackage.GOAL__OPERAT:
				return getOperat();
			case GMPackage.GOAL__DEFINITION:
				return getDefinition();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GMPackage.GOAL__DESCRIPTION:
				setDescription((String)newValue);
				return;
			case GMPackage.GOAL__LEAF:
				setLeaf((Boolean)newValue);
				return;
			case GMPackage.GOAL__PRIORITY:
				setPriority((Integer)newValue);
				return;
			case GMPackage.GOAL__REF:
				setRef((RefinementLink)newValue);
				return;
			case GMPackage.GOAL__SON_OF:
				setSonOf((RefinementLink)newValue);
				return;
			case GMPackage.GOAL__CONTR:
				getContr().clear();
				getContr().addAll((Collection<? extends ContributionLink>)newValue);
				return;
			case GMPackage.GOAL__OPERAT:
				getOperat().clear();
				getOperat().addAll((Collection<? extends Operation>)newValue);
				return;
			case GMPackage.GOAL__DEFINITION:
				setDefinition((Definition)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GMPackage.GOAL__DESCRIPTION:
				setDescription(DESCRIPTION_EDEFAULT);
				return;
			case GMPackage.GOAL__LEAF:
				setLeaf(LEAF_EDEFAULT);
				return;
			case GMPackage.GOAL__PRIORITY:
				setPriority(PRIORITY_EDEFAULT);
				return;
			case GMPackage.GOAL__REF:
				setRef((RefinementLink)null);
				return;
			case GMPackage.GOAL__SON_OF:
				setSonOf((RefinementLink)null);
				return;
			case GMPackage.GOAL__CONTR:
				getContr().clear();
				return;
			case GMPackage.GOAL__OPERAT:
				getOperat().clear();
				return;
			case GMPackage.GOAL__DEFINITION:
				setDefinition((Definition)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GMPackage.GOAL__DESCRIPTION:
				return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description);
			case GMPackage.GOAL__LEAF:
				return leaf != LEAF_EDEFAULT;
			case GMPackage.GOAL__PRIORITY:
				return priority != PRIORITY_EDEFAULT;
			case GMPackage.GOAL__REF:
				return ref != null;
			case GMPackage.GOAL__SON_OF:
				return sonOf != null;
			case GMPackage.GOAL__CONTR:
				return contr != null && !contr.isEmpty();
			case GMPackage.GOAL__OPERAT:
				return operat != null && !operat.isEmpty();
			case GMPackage.GOAL__DEFINITION:
				return definition != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (description: ");
		result.append(description);
		result.append(", leaf: ");
		result.append(leaf);
		result.append(", priority: ");
		result.append(priority);
		result.append(')');
		return result.toString();
	}

} //GoalImpl
